#include "../../include/object/error.hpp"

namespace malt
{
Error::Error() {}
Error::Error(String *Name, String *Body = (String *)MaltNullptr)
{
	ErrName = Name;
	ErrBody = Body;
}

Error::Error(const Error &obj)
{
	ErrName = obj.ErrName;
	ErrBody = obj.ErrBody;
}
bool Error::eq(Object *obj)
{
	return this == obj;
}
void Error::repl_print()
{
	char *ss = NULL;
	//sscanf(ErrName->chars, ErrBody->chars, (const char *), ss);
	fprintf(stderr, "\e[31;1m<%s: %s>\e[0m", ErrName->chars, ErrBody->chars);
}

void Error::marking()
{
	ErrName->marking();
	if (ErrBody != MaltNullptr)
		ErrBody->marking();
}

Error *merrno;
Error
		RuntimeError,
		SyntexError,
		ArgsLengthError;

#define B_Error(X, Y) \
	X.ErrName = (String *)NewString(CopyStr(Y, sizeof(Y)), sizeof(Y));

void ErrorInit()
{
	char rte[] = "RuntimeError";
	char rtb[] = "这不是解释器抛出的错误，我特么咋知道是啥玄学Bug";
	B_Error(RuntimeError, "RuntimeError");
	RuntimeError.ErrBody = (String *)NewString(CopyStr(rtb, sizeof(rtb)), sizeof(rtb));

	B_Error(SyntexError, "SyntexError");
	B_Error(ArgsLengthError, "ArgsLengthError");

	// ...
}
}